

namespace Stee.CAP8.MessageBus.Kafka.Tool
{
    using System;
    using NLog;
    using Stee.CAP8.MessageBus.Kafka.Tool.Menu;

    internal class Program
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();


        private static readonly AdminMenu AdminMenu = new AdminMenu();


        protected Program() { }


        internal static void Main()
        {
            try
            {
                var isInitialized = AdminMenu.InitializeAdminClient();
                var hasTopicConfig = false;
                var isCreated = false;

                if (isInitialized)
                {
                    hasTopicConfig = AdminMenu.GetJSONTopicConfigurations();
                }

                if (hasTopicConfig)
                {
                    var t = AdminMenu.CreateTopics();
                    t.Wait();
                    isCreated = t.Result;
                }

                Console.WriteLine(isCreated ?
                    "Topics has been created successfully." :
                    "Error encountered while creating topics. View logs for more details.");

                Console.WriteLine($"{Environment.NewLine}END.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                throw;
            }
        }
    }
}
